package com.programmercarl.backtracking;

import java.util.*;

/**
 * https://leetcode.cn/problems/combinations/
 *
 * @author yulongtian
 * @create 2024-12-29 10:23
 */
public class Test01 {
    public static void main(String[] args) {


    }

    List<List<Integer>> res;
    Deque<Integer> path;

    public List<List<Integer>> combine(int n, int k) {
        res = new ArrayList<>();
        path = new ArrayDeque<>();
        backTracking(n, k, 1);
        return res;
    }

    public void backTracking(int n, int k, int startIndex) {
        if (path.size() == k) {
            res.add(new ArrayList<>(path));
            return;
        }
        for (int i = startIndex; i <= n; i++) {
            path.push(i);
            backTracking(n, k, i + 1);
            path.pop();
        }
    }

}
